package com.flydust.apipulse;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.nio.file.Paths;

@SpringBootApplication
public class ApiPulseApplication implements WebMvcConfigurer {

	public static void main(String[] args) {
		SpringApplication.run(ApiPulseApplication.class, args);
	}
	
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		// 获取项目根目录下的uploads文件夹的绝对路径
		String uploadsPath = Paths.get("uploads").toAbsolutePath().toString();
		// 添加对上传目录的静态资源映射
		registry.addResourceHandler("/uploads/**")
				.addResourceLocations("file:" + uploadsPath + "/");
	}
}